﻿<DataListSpec 
	xmlns="bb_appfx_datalist"
	xmlns:common="bb_appfx_commontypes" 
	ID="13e64ae4-3d52-4513-9a8b-a00da35264ee" 
	Name="Duplicate Constituents Data List"
	Description="Returns a list of duplicate constituent based on the provided criteria." 
	Author="Blackbaud Professional Services"
	common:SecurityUIFolder="Service Bus Adapter">

	<!-- define the SP that returns the data for the datalist -->
	<SPDataList SPName="USR_USP_DATALIST_DUPLICATECONSTITUENTS">
		<common:CreateProcedureSQL>
			<![CDATA[
create procedure dbo.USR_USP_DATALIST_DUPLICATECONSTITUENTS(
  @CONSTITUENTTYPE int = 0, -- 0 = individuals, 1 = organizations
  @KEYNAME nvarchar(100),  
  @FIRSTNAME nvarchar(50) = '',  
  @POSTCODE nvarchar(12),  
  @ADDRESSBLOCK nvarchar(150) = '',
  @MINIMUMMATCHPERCENTAGE decimal(5,2) = 90
  )
as
	set nocount on;

	select 
    CONSTITUENTID,
    ADDRESSID,
    MATCHPERCENTAGE
	from 
    dbo.UFN_CONSTITUENT_GETFUZZYDUPLICATES(@KEYNAME, @FIRSTNAME, @POSTCODE, @ADDRESSBLOCK) dupes
  where
    dupes.MATCHPERCENTAGE >= @MINIMUMMATCHPERCENTAGE
			]]>
		</common:CreateProcedureSQL>
	</SPDataList>

	<Parameters>
		<common:FormMetaData>
			<common:FormFields>
        <common:FormField FieldID="CONSTITUENTTYPE" Caption="Constituent type" DataType="Integer">
          <common:ValueList>
            <common:Items>
              <common:Item>
                <common:Value>1</common:Value>
                <common:Label>Individual</common:Label>
              </common:Item>
              <common:Item>
                <common:Value>2</common:Value>
                <common:Label>Organization</common:Label>
              </common:Item>
            </common:Items>
          </common:ValueList>
        </common:FormField>
        <common:FormField FieldID="KEYNAME" Caption="Last/organization name" DataType="String" MaxLength="100"/>
        <common:FormField FieldID="FIRSTNAME" Caption="First name" DataType="String" MaxLength="50"/>
        <common:FormField FieldID="POSTCODE" Caption="Postal code" DataType="String" MaxLength="12"/>
        <common:FormField FieldID="ADDRESSBLOCK" Caption="Address" DataType="String" MaxLength="150"/>
        <common:FormField FieldID="MINIMUMMATCHPERCENTAGE" Caption="Minimum match %" DataType="Decimal" Precision="5" Scale="2" />
			</common:FormFields>
		</common:FormMetaData>
	</Parameters>

	<!-- define the output fields in the list -->
	<Output>
		<OutputFields>
			<OutputField FieldID="CONSTITUENTID" Caption="Constituent ID" DataType="Guid" />
      <OutputField FieldID="ADDRESSID" Caption="Address ID" DataType="Guid" />
      <OutputField FieldID="MATCHPERCENTAGE" Caption="Match %" DataType="Decimal" />
		</OutputFields>
	</Output>

</DataListSpec>
